﻿using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;
using HiauPdm.Bll;
using HiauPdm.Web;

namespace HiauPdm.Web
{
    public partial class PdmTop : PageBase
    {
        protected override bool IsAccess()
        {
            return true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                divLogin.InnerText = string.Format("当前登录：[{0}]", Session["RealName"]);
                DataSet dsMenu = BMain.GetChildMenu(0, (int)Session["UserId"]);
                if ((dsMenu != null) && (dsMenu.Tables[0].Rows.Count > 0))
                {
                    StringBuilder sMenu = new StringBuilder();
                    foreach (DataRow dr in dsMenu.Tables[0].Rows)
                    {
                        sMenu.AppendFormat("\r\n<a href=\"javascript:void(0);\" onfocus=\"blur();\" onclick=\"if(parent.frameLeft.location.href.lastIndexOf('{0}?MenuId={1}&MenuName={2}')>=0)return;parent.frameLeft.location.replace('{0}?MenuId={1}&MenuName={2}');parent.frameMain.location.replace('PdmLogo.aspx');event.returnValue=false;\" title='{3}'>{3}</a> |", dr["模块调用"], dr["ID"], Server.UrlEncode((string)dr["模块名称"]), dr["模块名称"]);
                    }
                    divMenu.InnerHtml = sMenu.ToString(0, sMenu.Length - 2);
                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "LoadLeftMenu", "window.onload=function(){parent.frameLeft.location.replace('" + string.Format("{0}?MenuId={1}&MenuName={2}", dsMenu.Tables[0].Rows[0]["模块调用"], dsMenu.Tables[0].Rows[0]["ID"], Server.UrlEncode((string)dsMenu.Tables[0].Rows[0]["模块名称"])) + "');parent.frameMain.location.replace('PdmLogo.aspx');};", true);
                }
                else
                {
                    divMenu.InnerHtml = string.Empty;
                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "LoadLeftMenu", "window.onload=function(){parent.frameLeft.location.replace('PdmLeft.aspx');parent.frameMain.location.replace('PdmLogo.aspx');};", true);
                }
                StringBuilder sMenuLogout = new StringBuilder();
                sMenuLogout.AppendFormat("\r\n<a href=\"javascript:void(0);\" onfocus=\"blur();\" onclick=\"parent.frameMain.location.replace('{0}');event.returnValue=false;\" title='{1}'>{1}</a> |", "ChangePwd.aspx", "修改密码");
                sMenuLogout.AppendFormat("\r\n<a href=\"javascript:void(0);\" onfocus=\"blur();\" onclick=\"parent.location.replace('{0}');event.returnValue=false;\" title='{1}'>{1}</a> |", "../Logout.aspx?ReLogin=ReLogin", "重新登录");
                sMenuLogout.AppendFormat("\r\n<a href=\"javascript:void(0);\" onfocus=\"blur();\" onclick=\"parent.location.replace('{0}');event.returnValue=false;\" title='{1}'>{1}</a>", "../Logout.aspx", "安全退出");
                divBottomRight.InnerHtml = sMenuLogout.ToString();
            }
        }
    }
}